const Base = require('./base')
module.exports = class extends Base {
  async __before () {
    const Serv = this.service('base')
    const {id} = this.ctx.param()
    if (!id) return this.fail(-1, '参数不能为空')
    this.accessToken = await Serv.get_access_token(id)
    if (!this.accessToken) return this.fail('无权限访问api')
  }
  /**
   * 查看卡券详情
   */
  async getAction () {
    const {card_id} = this.post()
    const d = await yy.http.post(`https://api.weixin.qq.com/card/get?access_token=${this.accessToken}`, {card_id})
    this.success(d)
  }
  /**
   * 批量查询卡券列表
   */
  async listAction () {
    const {offset, count, status_list} = this.post()
    const d = await yy.http.post(`https://api.weixin.qq.com/card/batchget?access_token=${this.accessToken}`, {offset, count, status_list})
    this.success(d)
  }
  /**
   * 更改卡券信息接口
   */
  async updateAction () {
    const {card_id, member_card} = this.post()
    const d = await yy.http.post(`https://api.weixin.qq.com/card/update?access_token=${this.accessToken}`, {card_id, member_card})
    this.success(d)
  }
}
